#!/bin/bash
set -e

TMP=${TMP:-/tmp/work}
LOG=${LOG:-$HOME/logs/stage1}
SRC=${SRC:-$LFS/sources}

mkdir -pv $TMP $LOG

name=bash
version=5.1

rm -rf $TMP
mkdir -p $TMP $LOG

tar xf $SRC/$name-$version.tar.gz -C $TMP

{ time \
   {
    
    cd $TMP/$name-$version

    ./configure --prefix=/usr                   \
                --build=$(support/config.guess) \
                --host=$LFS_TGT                 \
                --without-bash-malloc

    make

    make DESTDIR=$LFS install

    mv $LFS/usr/bin/bash $LFS/bin/bash

    ln -sv bash $LFS/bin/sh

    }
} 2>&1 | tee $name.log

[ $PIPESTATUS = 0 ] && mv $name.log $LOG || exit $PIPESTATUS

rm -fr $TMP
